
// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'

// ============================== 导出混合 ============================== //

export default {
  /**
   * 名称定义 (实际使用名称)
   */
  name: 'PointGroup',

  /**
   * 混入列表 (配置选项合并)
   */
  mixins: [CORE.mixWeb(), CORE.mixSelect('point', 'point_')],

  /**
   * 本地方法 (轻量重要在前)
   */
  methods: {
    /**
     * 保存
     */
    getProps(bind) {
      const key = CORE.key(bind)
      const trans = (label, type) => ({ label, bind: `key, ${key}Text`, dict: this.GETTER[`${type}Point`] })

      const { point_ai_prop: AI, point_ao_prop: AO, point_di_prop: DI, point_do_prop: DO } = CORE.DICT
      let matched

      matched = (AI || []).find((dict) => dict[2] === bind)
      if (matched) return trans(matched[1], 'ai')

      matched = (AO || []).find((dict) => dict[2] === bind)
      if (matched) return trans(matched[1], 'ao')

      matched = (DI || []).find((dict) => dict[2] === bind)
      if (matched) return trans(matched[1], 'di')

      matched = (DO || []).find((dict) => dict[2] === bind)
      if (matched) return trans(matched[1], 'do')
    },
  },
}
